<template>
  <div class="passenger-station-left-bottom">
    <div class="chart-title">
      <span class="title-icon"></span>
      <div class="title-text">今日客流量排行</div>
    </div>
    <div class="chart">
      <screen-chart @initCb="initChart"></screen-chart>
    </div>
  </div>
</template>

<script lang="ts">
import { barOptions } from './option'
import { Component, Vue } from 'vue-property-decorator'
import nanningScreenCascader from 'components/nanning-screen-cascader/index.vue'
import nanningScreenSelect from 'components/nanning-screen-select/index.vue'
import { getPassengersTop } from '@/api/situationAwareness/passengerStation/passengerStation'

@Component({
  name: 'passenger-station-left-bottom',
  components: {
    nanningScreenCascader,
    nanningScreenSelect
  }
})

export default class PassengerStationLeftBottom extends Vue {
  private currentTab = 1

  private avaChart: any = null

  private chartData = {
    data: []
  }

  private initChart(chart: any): void {
    this.avaChart = chart
    chart.clear()
    setTimeout(() => {
      this.avaChart.setOption(barOptions(this.chartData))
    }, 200)
  }

  async mounted () {
    await this.getPassengersTop()
  }
  async getPassengersTop () {
    const params = {
      dzcode: ''
    }
    try {
      const res: any = await getPassengersTop(params)
      console.log(res)
      this.chartData.data = []
      res.data.forEach((item: any) => {
        const ob = {
          name: item.name,
          value: item.total
        }
        // @ts-ignore
        this.chartData.data.push(ob)
      })
      this.initChart(this.avaChart)
    } catch (err) {
      console.error(err)
    }
  }
}
</script>

<style lang="scss" scoped>
.passenger-station-left-bottom {
  width: 100%;
  height: 58%;
  .chart-title {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    font-size: 18px;
    font-family: 'PingFang Regular';
    font-weight: 500;
    color: #FFFFFF;
    margin: 10px 20px;
    height: 25px;
    .title-icon {
      display: inline-block;
      width: 10px;
      height: 10px;
      background-color: #23fffc;
      border-radius: 50%;
      margin-right: 4px;
    }
  }
  .chart {
    width: 100%;
    height: 80%;
  }
}
</style>
